var wpfdColorboxInit; var loading; jQuery(document).ready(function ($){ var videoTypes=['m4a', 'mp4', 'webm', 'ogg', 'ogv', 'flv']; var audioTypes=['mp3', 'wav', 'wma', 'm4a']; var imageTypes=['jpg', 'png', 'gif', 'jpeg', 'jpe', 'bmp', 'ico', 'tiff', 'tif', 'svg', 'svgz']; (wpfdColorboxInit=function (){ $('.wpfdlightbox').each(function (){ var filetype=$(this).data('file-type'); var previewLink=$(this).prop('href'); sW=$(window).width(); sH=$(window).height(); sR=sW / sH; $(this).unbind('click').click(function (e){ e.preventDefault(); fileid=$(this).data('id'); catid=$(this).data('catid'); downloadLink=wpfdcolorbox.wpfdajaxurl + 'action=wpfd&task=file.download&wpfd_category_id=' + catid + '&wpfd_file_id=' + fileid + '&preview=1'; if($(this).hasClass('wpfd_previewlink')){ var href=jQuery(this).attr('href'); var extLink=href.replace(/^https?\:\/\//i, ''); if(typeof (_gaq)!=='undefined'){ _gaq.push(['_trackEvent', 'WPFD', 'Preview', extLink]); }else if(typeof (ga)!=="undefined"){ ga('send', 'event', 'WPFD', 'Preview', extLink); }} if(typeof fileid=='string'){ while (fileid.indexOf(':') > -1){ fileid=fileid.replace(':', '-'); }} html='
'; html +=' '; if(audioTypes.indexOf(filetype) > -1){ html +=''; }else if(imageTypes.indexOf(filetype) > -1){ html +=' '; }else if(videoTypes.indexOf(filetype) > -1){ html +=''; }else if(previewLink.includes('file.preview')||previewLink.includes('/previews/')){ html +='
'; html +=' '; html +='
' }else{ viewlink=$(this).attr('href'); html +=''; } html +='
'; loader=$("#wpfd-box-loading"); if(loader.length===0){ $('body').append(''); loader=$("#wpfd-box-loading"); } loader.show(); $(document).unbind('click', '#wpfd-box-loading, .wpfd-loading-close').on('click', '#wpfd-box-loading, .wpfd-loading-close', function (){ $("#wpfd-box-loading").remove(); }); var timeout=5000; loading=setTimeout(function(){ var currentLoading=$('#wpfd-box-loading'); if(currentLoading.length > 0){ $('.wpfd-loading-status', currentLoading).remove(); var status=$('
' + wpfdcolorboxvars.preview_loading_message + '
'); currentLoading.append(status); }}, timeout); pBox=$("#wpfd-box-player"); if(pBox.length===0){ $('body').append(''); pBox=$("#wpfd-box-player"); } pBox.hide(); pBox.empty(); pBox.prepend(html); $('#wpfd-dropblock-close').click(function(e){ e.preventDefault(); pBox.hide(); if($("#player-"+fileid).length){ myPlayer=videojs("player-"+fileid); myPlayer.dispose(); }}); pBox.click(function (e){ if($(e.target).is('#wpfd-box-player')){ pBox.hide(); if($("#player-" + fileid).length){ myPlayer=videojs("player-" + fileid); myPlayer.dispose(); }} $('#wpfd-box-player').unbind('click.box').bind('click.box', function (e){ if($(e.target).is('#wpfd-box-player')){ pBox.hide(); }}); }); if(imageTypes.indexOf(filetype) > -1||previewLink.includes('file.preview')||previewLink.includes('/previews/')){ new_img=new Image(); new_img.onload=function (){ var img_width=this.width, img_heigth=this.height; vR=img_width / img_heigth; if(vR > sR){ new_vW=parseInt(sW * 0.9); new_vH=parseInt(new_vW / vR); }else{ new_vH=parseInt(sH * 0.9); new_vW=parseInt(new_vH * vR); } if(new_vW > img_width&&new_vH > img_heigth){ new_vW=img_width; new_vH=img_heigth; } $("#player-" + fileid).css('width', '100%'); $("#player-" + fileid).css('maxHeight', 'unset'); loader.hide(0, function(){ clearTimeout(loading); }); pBox.show(); } if(previewLink.includes('file.preview')||previewLink.includes('/previews/')){ new_img.src=previewLink; }else{ new_img.src=downloadLink; }}else if(videoTypes.indexOf(filetype) > -1||(audioTypes.indexOf(filetype) > -1)){ videojs("player-" + fileid, {}, function (){ var myPlayer=this; if(audioTypes.indexOf(filetype) > -1){ new_vW=350; new_vH=60; myPlayer.dimensions(new_vW, new_vH); loader.hide(0, function(){ clearTimeout(loading); }); pBox.show(); }else{ myPlayer.on('loadedmetadata', function (){ var v=document.getElementById('player-' + fileid + '_html5_api'); vW=v.videoWidth; vH=v.videoHeight; vR=vW / vH; if(vR > sR){ new_vW=parseInt(sW * 0.9); new_vH=parseInt(new_vW / vR); }else{ new_vH=parseInt(sH * 0.9); new_vW=parseInt(new_vH * vR); } myPlayer.dimensions(new_vW, new_vH); loader.hide(0, function(){ clearTimeout(loading); }); pBox.show(); }); } myPlayer.on('error', function (){ error=myPlayer.error(); myPlayer.dispose(); pBox.empty(); pBox.prepend('
' + error.message + '
'); new_vW=300; new_vH=200; var dropblock=pBox.find('.dropblock'); dropblock.css('width', new_vW).css('height', new_vH); loader.hide(0, function(){ clearTimeout(loading); }); pBox.show(); }) }); }else{ new_vW=sW * 0.9; new_vH=sH * 0.9; var dropblock=pBox.find('.dropblock'); dropblock.css('width', new_vW).css('height', new_vH); $('.dropblock iframe').on('load', function (){ loader.hide(0, function(){ clearTimeout(loading); }); pBox.show(); }) }}); }); })(); centerDropblock=function (fileid, margin_top, margin_left){ var dropblock=$("#player-" + fileid).parent('.dropblock'); dropblock.css('margin-top', (-margin_top) + 'px'); dropblock.css('margin-left', (-margin_left) + 'px'); dropblock.css('height', ''); dropblock.css('width', ''); dropblock.css('top', ''); dropblock.css('left', ''); }}); jQuery(document).keyup(function (e){ if(e.keyCode==27){ pBox=jQuery("#wpfd-box-player"); if(pBox.length){ pBox.hide(); if(pBox.find(".video-js").length){ var playerId=pBox.find(".video-js").first().attr("id"); myPlayer=videojs(playerId); myPlayer.dispose(); }} }});